﻿
@{
    ViewBag.Title = "密码";
    Layout = "~/Views/Shared/_Layout.cshtml";

    ViewBag.LeftTitle = "设 置";
    ViewBag.MainMenu = "Settings";
    ViewBag.LeftMenu = "Personal";
}

<script src="~/Scripts/MD5.js" type="text/javascript"></script>

<script>

    $(document).ready(function ()
    {
        $("[keyenter]").keypress(function (e)
        {
            if (e.keyCode == 13)
            {
                save();
            }
        });
    });

    function save()
    {
        if ($("#form").validate({
            rules: {
                       "txtPassword": "required",
                       "txtNewPassword": "required",
                       "txtNewPassword2": {
                            required: true,
                            minlength: 3,
                            equalTo: "#txtNewPassword"
                        }
                        },
            messages: {
                       "txtPassword": "!",
                       "txtNewPassword": "!",
                       "txtNewPassword2": {
                            required: "!",
                            minlength: "!",
                            equalTo: "!"
                        }
                        }
        }).form() == false)
        {
            return;
        }

        var args = new Object();
        args.Password = hex_md5($("#txtPassword").val()).toUpperCase();
        args.NewPassword = hex_md5($("#txtNewPassword").val()).toUpperCase();
        
        var layerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        $.ajax({
            url: "/Api/User/UpdatePassword",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(args),
            success: function (data, status, jqXHR)
            {
                if (data.Success)
                {
                    layer.close(layerIndex);

                    //layer.msg("密码已更新。", {
                    //    time: 1000
                    //});

                    layerAlert("密码已更新，下次请使用新密码登录。");

                    $("#txtPassword").val("");
                    $("#txtNewPassword").val("");
                    $("#txtNewPassword2").val("");

                } else
                {
                    layer.closeAll();

                    layerAlert("密码更新失败，请确认当前密码输入是否正确。");
                }
            },
            error: function (xmlHttpRequest)
            {
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

</script>

    <div id="divContent">
        <div id="divContainerTitle">
            个人
        </div>
        <div style=" margin-top:20px;">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td class="td_ContentTab_active">密码</td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td colspan="3" bgcolor="#D4D4D4" height="1"></td>
                </tr>
            </table>

        </div>
        <div style="margin-left:40px;margin-bottom:30px;margin-top:30px;">
            <form id="form">
                <table width="540" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="150" height="50">当前密码：</td>
                        <td><input name="txtPassword" type="password" class="input_18" style="width:350px;" id="txtPassword" keyenter /> *</td>
                    </tr>
                    <tr>
                        <td height="50">新密码：</td>
                        <td><input name="txtNewPassword" type="password" class="input_18" style="width:350px;" id="txtNewPassword" keyenter /> *</td>
                    </tr>
                    <tr>
                        <td height="50">重复输入新密码：</td>
                        <td><input name="txtNewPassword2" type="password" class="input_18" style="width:350px;" id="txtNewPassword2" keyenter /> *</td>
                    </tr>
                    <tr>
                        <td height="50">&nbsp;</td>
                        <td>
                            <span class="font_gray_15" style="">密码至少3位以上</span>
                        </td>
                    </tr>
                </table>
                </form>
</div>
        <div style="margin-left:40px;">

            <table width="500" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td height="50"><input name="btnSave" type="button" class="btn_blue" id="btnSave" value="保 存" onclick="save()" /></td>
                </tr>

            </table>
        </div>

    </div>
